package cn.cjxy.service.impl;

import cn.cjxy.domain.User;
import cn.cjxy.mapper.UserMapper;
import cn.cjxy.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service//先继承后实现 第一个参数为当前service所对应的mapper层接口，第二个参数为实体类
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    //完成登录 此处写逻辑
    @Override
    public User login(User user) {
        //先判断是否为空
        if (user==null || user.getName()==null){
            throw  new RuntimeException("用户名或密码为空！请重新输入");
        }
        //不为空

        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("name",user.getName());
        User user1 = userMapper.selectOne(userQueryWrapper);
        //不对的情况
        if (user1==null){
            throw  new RuntimeException("用户名或密码错误！");
        }
        return user1;
    }



}
